import { API_EVENT, IReq, IRes } from "../interface";
import { Connector } from "cax-connector";
import { v4 as uuidv4 } from "uuid";

export function delete_entity(
  this: Connector,
  parts: any[],
  type: number
): Promise<any> {
  console.log("parts", parts);

  if (this.client == null) return Promise.reject("socket未初始化");
  const req: IReq = {
    Topic: "api",
    Type: API_EVENT.DELETE_ENTITY,
    // todo 后续需要传入类型
    Params: {
      parts,
      type,
    },
    Req: 1,
    Res: 0,
    Tag: uuidv4(),
  };
  this.client.emit("api", req);
  return new Promise((resolve, reject) => {
    this.client?.once(req.Tag, (ev: IRes) => {
      console.log("-----ev-----", ev);
      resolve(ev.Result.Status);
    });
  });
}
